<h4><?php echo $num_mails; ?></h4>
<div id="accordion" class="accordion">
<?php
$count = 0;
krsort($emails);
foreach($emails as $i=>$e)
{
    $data = strtotime($e['date']);
    echo '<div class="accordion-group">'
            .'<div class="accordion-heading">'
                .'<div class="mail-box left label label-info">'
                    .'#'.$i
                .'</div>'
                .'<div class="mail-box left span10">'
                    .'<a href="#tab-'.$i.'" data-parent="#accordion" data-toggle="collapse" class="accordion-toggle left">'
                        .'<strong>'.$e['subj'].'</strong>'
                    .'</a>'
                    .'<small><strong>Od:</strong> '.$e['from'].' - '.$e['autor'][0].'</small><br/>'
                    .'<small><strong>Odebrano dnia:</strong> '.date('d-m-Y',$data).' <strong>o godz.:</strong> '.date('H:i:s',$data).'</small>'
                .'</div>'
            .'</div>'
            .'<div id="tab-'.$i.'" class="clear accordion-body'.(($count==0) ? ' in' : '').' collapse">'
                .'<div class="accordion-inner">'
                    .$e['body']
                .'</div>'
            .'</div>'
        .'</div>';
    $count++;
}
?>
</div>